﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Reflection;
using ExperimentUpon.Service.Impl;

namespace ExperimentUpon.Service
{
    public class ServiceFactory
    {
        private static Hashtable serviceTable = new Hashtable();

        static ServiceFactory() 
        {
            serviceTable.Add(typeof(IStudentService),
                CreateServiceByType<StudentServiceImpl>());
            serviceTable.Add(typeof(IUserService), 
                CreateServiceByType<UserServiceImpl>());
        }

        private static T CreateServiceByType<T>()
        {
            return (T)Activator.CreateInstance(typeof(T));
        }

        public static T GetService<T>()
        {
            return (T)serviceTable[typeof(T)];
        }

        public static T CreateService<T>()
        {
            return (T)Activator.CreateInstance(serviceTable[typeof(T)].GetType());
        }


    }
}
